import 'package:flutter/material.dart';
import '../../model/space_item.dart';
import '../../spaces/recordspace/record_list.dart';

import '../../helper/Helper.dart';
import '../../helper/global_config.dart';
import '../../helper/uidata.dart';
import '../../model/report.dart';

class ReportItemAddPage extends StatefulWidget {
  @override
  ReportItemAddPage(this.spaceId, this.added);
  final String spaceId;
  final RecordAddCallback added;
  @override
  ReportItemAddPageState createState() => new ReportItemAddPageState();
}

class ReportItemAddPageState extends State<ReportItemAddPage> {
  // final TextEditingController c1=new TextEditingController();
  final TextEditingController c2 = new TextEditingController();

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }

  upload(BuildContext context) async {
    if (c2.text == "") return;
    // var a=new Report(0, Helper.GetGuid(), widget.spaceId, "", c2.text, UIData.CurrentUser!.Guid, Helper.DateTimeNowString());
    // var pb1= await  Report.Add(a);

    var a = new SpaceItem(
        0,
        Helper.GetGuid(),
        UIData.CurrentUser!.Guid,
        widget.spaceId,
        3,
        "",
        Helper.DateTimeNowString(),
        0,
        0,
        "",
        c2.text,
        "",
        "",
        "",
        "");
    var pb1 = await SpaceItem.Add(a);
    if (pb1 == true) {
      widget.added(a);
      Navigator.of(context).pop();
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      //backgroundColor: Colors.white,
      appBar: AppBar(
        title: Text("添加文字记录"),
        actions: <Widget>[
          ElevatedButton(
            // color: Colors.blue,
            //  textColor: Colors.white,
            child: Text("保存"),
            onPressed: () {
              //upLoadImg();
              upload(context);
            },
          )
        ],
      ),
      body: ReportItemAddBody(context),
    );
  }

  ReportItemAddBody(BuildContext context) => SingleChildScrollView(
        child: ReportItemAddFields(context),
      );

  ReportItemAddFields(BuildContext context) => Container(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.end,
          children: <Widget>[
            Container(
              margin: EdgeInsets.all(8.0),
              //color: Colors.white,
              child: TextField(
                maxLines: null,
                controller: c2,
                style:
                    TextStyle(fontSize: 16.0, color: Colors.black, height: 1.5),
                decoration: InputDecoration(
                  hintText: "主要内容",
                ),
              ),
            ),
          ],
        ),
      );
}
